package com.lmind.core.gps.tm;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicLong;

import com.lmind.core.async.FutureResult;
import com.lmind.core.gps.terminal.Terminal;
import com.lmind.core.gps.terminal.message.AbstractMessage;
import com.lmind.core.message.DuplexMessagePipe;
import com.lmind.core.message.MessagePipe;

public class TerminalSession {
	
	private Terminal terminal;
	
	private MessagePipe messagePipe;
	
	private AtomicLong seq = new AtomicLong(1);
	
	private Queue<FutureResult<AbstractMessage>> watingQueue = 
			new LinkedBlockingQueue<FutureResult<AbstractMessage>>();

	public TerminalSession() {
		
	}

	public Terminal getTerminal() {
		return terminal;
	}

	public void setTerminal(Terminal terminal) {
		this.terminal = terminal;
	}

	public MessagePipe getMessagePipe() {
		return messagePipe;
	}

	public void setMessagePipe(MessagePipe messagePipe) {
		this.messagePipe = messagePipe;
	}
	
	public Queue<FutureResult<AbstractMessage>> getWatingQueue() {
		return watingQueue;
	}
	
	public void close() {
		interruptWatingQueue();
	}
	
	protected void interruptWatingQueue() {
		for (FutureResult<AbstractMessage> result : watingQueue) {
			result.interrupt();
		}
	}
}
